package me.module.toolMain.mainElement
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.utils.Dictionary;
	
	import me.common.GlobalCore;
	import me.vo.ActionVO;
	
	/**
	 * bitmap 播放器
	 * @author Quexi 
	 */	
	public class BitmapPlayer extends Sprite
	{
		public static var zeroPoint:Point = new Point(0, 0);
		public static var emptyBmd:BitmapData = new BitmapData(1,1);
		public static var playDely:int = 1;
	
		/**
		 * 第几行动作 
		 */		
		protected var line:int = 3;
		private var _actId:int = 0;
		private var _bitmapdata:BitmapData;
		
		private var _frame:uint = 0;
		private var _dely:int = 0;
		private var _action:ActionVO;
		
		public function BitmapPlayer()
		{
			_bitmapdata = emptyBmd;
		}
		
		/**
		 * 播放动画 
		 */		
		public function play(action:ActionVO,line:int):void
		{
			
			if(_action != action)
				_frame = 0;
			_action = action;
			this.line = line;
			_dely ++;
			if(_dely > playDely)
			{
				if(_frame < (_action.frameNum - 1))
					_frame  ++;
				else _frame = 0;
				_dely = 0;
				rander();
				
			}
		}
		
		/**
		 * 渲染一次 
		 */		
		private function rander():void
		{
			var resBmd:BitmapData;
			resBmd = GlobalCore.spriteDic[_action.name + line + "," + _frame];
//			trace(line,_frame)
			if(resBmd != null)
			{
				
				this.graphics.clear();
				this.graphics.beginBitmapFill(resBmd);
				this.graphics.drawRect(0,0,resBmd.width, resBmd.height);
				this.graphics.endFill();
			}
			else
			{
				_bitmapdata = emptyBmd;
				trace("fuck: "+_action.name, line, _frame);
			}
		}
		
		public function set currentFrame(value:uint):void
		{
			_frame = value;
		}
		
		public function get currentFrame():uint
		{
			return _frame;
		}
		
		
		//
	}
}